PROJECT (DEVSIM CXX)
cmake_minimum_required(VERSION 3.9)

set(DEVSIM_CONFIG "unknown" CACHE STRING "configuration to load from ./cmake")
OPTION(VTKWRITER    "Build with VTK Writer" ON)
OPTION(PYTHON3      "Build Python 3 Interpreter" ON)
OPTION(DEVSIM_EXTENDED_PRECISION "Build with extended precision" OFF)
OPTION(DEVSIM_CPP_BIN_FLOAT "Build with boost quadmath emulation" OFF)
OPTION(MKL_PARDISO  "Build with MKL Pardiso" ON)
OPTION(EIGEN_DENSE_EXTENDED "Use eigen for the dense matrix in extended precision" OFF)
OPTION(EIGEN_DENSE_DOUBLE "Use eigen for the dense matrix in double precision" OFF)
OPTION(SUPERLU_PRECONDITIONER "Use superlu for the preconditioner" OFF)
OPTION(DEVSIM_LOAD_MATHLIBS "Load BLAS/LAPACK libraries at startup" ON)
OPTION(STATICONLY    "Build static only" OFF)


set (CMAKE_CXX_STANDARD 17)

INCLUDE(${PROJECT_SOURCE_DIR}/cmake/${DEVSIM_CONFIG}.cmake OPTIONAL)
INCLUDE(${PROJECT_SOURCE_DIR}/local.cmake OPTIONAL)

#also change this in setup.cfg
ADD_DEFINITIONS(-DDEVSIM_VERSION_STRING=\"2.8.4\")
ADD_DEFINITIONS(-DDEVSIM_COPYRIGHT_YEAR=\"2009-2024\")

IF (MKL_PARDISO)
ADD_DEFINITIONS(-DUSE_MKL_PARDISO)
ENDIF (MKL_PARDISO)

IF (VTKWRITER)
ADD_DEFINITIONS(-DVTKWRITER)
ENDIF (VTKWRITER)

IF (EIGEN_DENSE_EXTENDED)
ADD_DEFINITIONS(-DUSE_EIGEN_EXTENDED)
ENDIF()
IF (EIGEN_DENSE_DOUBLE)
ADD_DEFINITIONS(-DUSE_EIGEN_DOUBLE)
ENDIF()

IF (SUPERLU_PRECONDITIONER)
ADD_DEFINITIONS(-DUSE_SUPERLU_PRECONDITIONER)
ENDIF()

IF (EIGEN_DENSE_EXTENDED OR EIGEN_DENSE_DOUBLE)
ADD_DEFINITIONS(-DEIGEN_MPL2_ONLY)
ENDIF()

IF (DEVSIM_LOAD_MATHLIBS)
ADD_DEFINITIONS(-DLOAD_MATHLIBS -DUSE_BLAS -DUSE_LAPACK -DUSE_ITERATIVE_SOLVER)
ENDIF()
IF ((NOT DEVSIM_LOAD_MATHLIBS) AND MKL_PARDISO)
MESSAGE(FATAL_ERROR "MKL_PARDISO requires DEVSIM_LOAD_MATHLIBS")
ENDIF()

IF (DEVSIM_CPP_BIN_FLOAT)
ADD_DEFINITIONS(-DUSE_CPP_BIN_FLOAT)
ENDIF()

IF (DEVSIM_CPP_BIN_FLOAT AND NOT EIGEN_DENSE_EXTENDED)
MESSAGE(FATAL_ERROR "CANNOT HAVE DEVSIM_CPP_BIN_FLOAT without EIGEN_DENSE_EXTENDED")
ENDIF()



INCLUDE_DIRECTORIES(${BOOST_INCLUDE})
IF (DEVSIM_EXTENDED_PRECISION)
ADD_DEFINITIONS(-DDEVSIM_EXTENDED_PRECISION)
ENDIF (DEVSIM_EXTENDED_PRECISION)

SET (SUBDIRS
    src
    testing
)

SITE_NAME(HOSTNAME)
MESSAGE("Hostname: ${HOSTNAME}")

ENABLE_TESTING()
FOREACH (SUB ${SUBDIRS})
    ADD_SUBDIRECTORY(${SUB})
ENDFOREACH (SUB ${SUBDIRS})

